package summer_drink_car

import (
	"wespy-http-go/app/activity/2025/summer_drink_car/conf"
	"wespy-http-go/app/activity/2025/summer_drink_car/cron"
	"wespy-http-go/app/activity/2025/summer_drink_car/event"
	"wespy-http-go/app/activity/2025/summer_drink_car/hook"
	"wespy-http-go/app/activity/2025/summer_drink_car/route"
	"wespy-http-go/app/activity/common/actevent"
	"wespy-http-go/app/activity/common/actmodel"
	rankStore "wespy-http-go/app/activity/widget/rank/store"
	"wespy-http-go/helper"
	"wespy-http-go/helper/cronext"
	"wespy-http-go/pkg/weconfig"
)

type DrinkCarModel struct {
	actmodel.DefaultModel
}

func (d *DrinkCarModel) GetActId() int {
	return conf.ActId
}

func (d *DrinkCarModel) GetRouter() actmodel.Router {
	if !helper.InArrayString(weconfig.GetServerRegion(), conf.RegionList) {
		return d.DefaultModel.GetRouter()
	}
	return actmodel.Router{
		Domain: "weplay_drink_car_summercamp",
		SubRouters: []actmodel.SubRouter{
			{
				Action:  "change_name",
				Handler: route.ChangeName,
			},
			{
				Action:  "open_door",
				Handler: route.OpenDoor,
			},
			{
				Action:  "send_flyer",
				Handler: route.SendFlyer,
			},
			{
				Action:  "get_tables",
				Handler: route.GetTables,
			},
			{
				Action:  "checkout_tables",
				Handler: route.CheckoutTables,
			},
			{
				Action:  "checkout_tip",
				Handler: route.CheckoutTip,
			},
			{
				Action:  "sign_in",
				Handler: route.SignIn,
			},
			{
				Action:  "get_sign_details",
				Handler: route.GetSignDetails,
			},
			{
				Action:  "get_sign_popup",
				Handler: route.GetSignPopup,
			},
			{
				Action:  "get_shop_details",
				Handler: route.GetShopDetails,
			},
			{
				Action:  "buy_advanced_book",
				Handler: route.BuyAdvancedBook,
			},
			{
				Action:  "get_rank_list",
				Handler: route.GetRankList,
			},
			{
				Action:  "test_hourly_rank",
				Handler: route.TestHourlyRank,
			},
			{
				Action:  "test_hourly_checkout",
				Handler: route.TestHourlyCheckout,
			},
		},
	}
}

func (d *DrinkCarModel) GetHookers() actmodel.ActHookerList {
	if !helper.InArrayString(weconfig.GetServerRegion(), conf.RegionList) {
		return d.DefaultModel.GetHookers()
	}

	rankStore.RegisterRankCheckoutHooker(conf.ActId, hook.GetRankCheckoutHooker())

	return actmodel.ActHookerList{}
}

func (d *DrinkCarModel) GetCronTasks() []*cronext.ActJob {
	if !helper.InArrayString(weconfig.GetServerRegion(), conf.RegionList) {
		return []*cronext.ActJob{}
	}

	return cron.GetHourlyRankCheckoutJobs()
}

func (d *DrinkCarModel) GetEvents() []actmodel.Event {
	if !helper.InArrayString(weconfig.GetServerRegion(), conf.RegionList) {
		return d.DefaultModel.GetEvents()
	}
	return []actmodel.Event{
		{
			Handler: event.HandleCollectChip,
			ActId:   d.GetActId(),
			Topic:   actevent.TopicCollectChip,
		},
	}
}

func (d *DrinkCarModel) GetDeferTasks() []actmodel.DeferTask {
	return []actmodel.DeferTask{
		{
			Handler:    event.HandleFreeFlyer,
			ActId:      conf.ActId,
			WithOffset: true,
			TaskName:   conf.DeferTaskFreeFlyer,
		},
		{
			Handler:    event.HandleCheckoutTable,
			ActId:      conf.ActId,
			TaskName:   conf.DeferTaskCheckout,
			WithOffset: true,
		},
	}
}
